const formatTime = (date) => {
  const pad = (n) => n.toString().padStart(2, '0');
  const year = date.getFullYear();
  const month = pad(date.getMonth() + 1);
  const day = pad(date.getDate());
  const hour = pad(date.getHours());
  const minute = pad(date.getMinutes());
  const second = pad(date.getSeconds());
  return `${year}/${month}/${day} ${hour}:${minute}:${second}`;
};

// 封装时分秒
const formatDuring = (mss, type) => {
  const days = Math.floor(mss / (1000 * 60 * 60 * 24));
  const hours = Math.floor((mss / (1000 * 60 * 60)) % 24).toString().padStart(2, '0');
  const minutes = Math.floor((mss / (1000 * 60)) % 60).toString().padStart(2, '0');
  const seconds = Math.floor((mss / 1000) % 60).toString().padStart(2, '0');

  if (type === 1) {
    return days > 0 ? `${days}:${hours}:${minutes}:${seconds}` : `${hours}:${minutes}:${seconds}`;
  } else if (type === 2) {
    return days > 0 ? `${days}天${hours}小时${minutes}分${seconds}秒` : `${hours}小时${minutes}分${seconds}秒`;
  }
};


module.exports = {
  formatTime,
  formatDuring,
};
